<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <button id="btn">防抖</button>
    
</body>
</html>
<script>
    // 防抖
    function debounce(fn, delay) {
        let timer = null
        // 返回一个箭头函数
        return (...args)=> {
            if (timer) clearTimeout(timer)
            timer = setTimeout(() => {
                fn.apply(this, args)
            }, delay)
        }
    }

    function handleClick(e) {
        console.log(e, 'click');
        console.log('防抖')
    }
    let btn = document.getElementById('btn')
    // btn.onclick = debounce(handleClick, 1000)
    btn.addEventListener('click', debounce(handleClick, 1000))
</script>